package cmich.cps.scheduler.data;

import java.security.Timestamp;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Transient;
import javax.persistence.Version;

import com.avaje.ebean.validation.NotNull;

/**
 * The Class Professor.
 * 
 * @author Jonathan Kissinger <kissi1j@cmich.edu>
 */
@Entity
public class Professor implements Comparable<Professor> {
	
	/** The id. */
	@Id
	@GeneratedValue
	int id;
	
	/** The last update. */
	@Version
	Timestamp lastUpdate;
	
	/** The name. */
	@NotNull
	private String name;
	
	/** The time between courses. */
	private String timeBetweenCourses;
	
	/** The max courses. */
	@NotNull
	private Integer maxCourses;
	
	/** The preferences. */
	@OneToMany(cascade=CascadeType.ALL)
	private List<Preference> preferences;
	
	/** The assigned courses. */
	@Transient
	private Integer assignedCourses = 0;

	/**
	 * Adds the preference.
	 *
	 * @param pref the pref
	 */
	public void addPreference(Preference pref) {
		if(this.preferences==null) {
			this.preferences = new ArrayList<Preference>();
		}
		this.preferences.add(pref);
	}
	
	/**
	 * Removes the preference.
	 *
	 * @param preference the preference
	 */
	public void removePreference(Preference preference) {
		this.preferences.remove(preference);
	}

	/**
	 * Gets the id.
	 *
	 * @return the id
	 */
	public int getId() {
		return id;
	}
	
	/**
	 * Sets the id.
	 *
	 * @param id the new id
	 */
	public void setId(int id) {
		this.id = id;
	}
	
	/**
	 * Gets the last update.
	 *
	 * @return the last update
	 */
	public Timestamp getLastUpdate() {
		return lastUpdate;
	}
	
	/**
	 * Sets the last update.
	 *
	 * @param lastUpdate the new last update
	 */
	public void setLastUpdate(Timestamp lastUpdate) {
		this.lastUpdate = lastUpdate;
	}
	
	/**
	 * Gets the name.
	 *
	 * @return the name
	 */
	public String getName() {
		return name;
	}
	
	/**
	 * Sets the name.
	 *
	 * @param name the new name
	 */
	public void setName(String name) {
		this.name = name;
	}
	
	/**
	 * Gets the time between courses.
	 *
	 * @return the time between courses
	 */
	public String getTimeBetweenCourses() {
		return timeBetweenCourses;
	}
	
	/**
	 * Sets the time between courses.
	 *
	 * @param timeBetweenCourses the new time between courses
	 */
	public void setTimeBetweenCourses(String timeBetweenCourses) {
		this.timeBetweenCourses = timeBetweenCourses;
	}
	
	/**
	 * Gets the max courses.
	 *
	 * @return the max courses
	 */
	public Integer getMaxCourses() {
		return maxCourses;
	}
	
	/**
	 * Sets the max courses.
	 *
	 * @param maxCourses the new max courses
	 */
	public void setMaxCourses(Integer maxCourses) {
		this.maxCourses = maxCourses;
	}
	
	/**
	 * Gets the preferences.
	 *
	 * @return the preferences
	 */
	public List<Preference> getPreferences() {
		return preferences;
	}
	
	/**
	 * Sets the preferences.
	 *
	 * @param preferences the new preferences
	 */
	public void setPreferences(List<Preference> preferences) {
		this.preferences = preferences;
	}
	
	/**
	 * Gets the assigned courses.
	 *
	 * @return the assigned courses
	 */
	public Integer getAssignedCourses() {
		return assignedCourses;
	}

	/**
	 * Sets the assigned courses.
	 *
	 * @param assignedCourses the new assigned courses
	 */
	public void setAssignedCourses(Integer assignedCourses) {
		this.assignedCourses = assignedCourses;
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return this.name;
	}

	/* (non-Javadoc)
	 * @see java.lang.Comparable#compareTo(java.lang.Object)
	 */
	@Override
	public int compareTo(Professor p) {
		return this.name.compareTo(p.getName());
	}
}